Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
Cannot update object value, keeps overwriting by strange id | javaScript Mongodb

I couldn't update object value and figure out how...

The thing I wan to do is if the frequency is one time, return query with 'creatorDetails.uuid' and measureId.

hasCompleted(userId) {
  // ...
  const query = {
    'creatorDetails.uuid': userId,
    measureId: this._id,
  };

  if (this.typeOptions.frequency === Frequency.ONE_TIME) {
    return query;
    console.log('query - inside', query);
  }
  // ...
  console.log('query - outside', query);
  return MeasureData.find(query).count() > 0;
}

But this didn't work well.

console.log('query - inside, query) shows

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "RMLY8unSwSJtRDde2"
}

console.log('query - outside, query) shows

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "PPt4tnGNxW34F5o8t" 
}

So I tried below.

hasCompleted(userId) {
  // ...
  const query = {
    'creatorDetails.uuid': userId,
    measureId: this._id,
  };

  if (this.typeOptions.frequency === Frequency.ONE_TIME) {
    // query.creatorDetails.uuid = userId; // this cause an error as well
    query.measureId = this._id; // added
    console.log('query - inside', query);
  }
  // ...
  console.log('query - outside', query);
  return MeasureData.find(query).count() > 0;
}

console.log('query - inside', query) shows the same

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "RMLY8unSwSJtRDde2"
}

console.log('query - outside', query) shows also the same

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "PPt4tnGNxW34F5o8t" 
}

Somehow measureId gets overwrote by a strange measureId PPt4tnGNxW34F5o8t

I also tried push inside of hasCompleted()

if (this.typeOptions.frequency === Frequency.ONE_TIME) {
  query.measureId.push(this._id)
} 

But I got an error saying query.measureId.push id not a function

Does anybody know how to update query? Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think there is a problem with the code:

You have to console first and then return otherwise it won't call the console.log because of unreachable statement

hasCompleted(userId) {
  // ...
  const query = {
    'creatorDetails.uuid': userId,
    measureId: this._id,
  };

  console.log(this.typeOptions.frequency, Frequency.ONE_TIME, this.typeOptions.frequency === Frequency.ONE_TIME);
  if (this.typeOptions.frequency === Frequency.ONE_TIME) {

    console.log('query - inside', query);
    return query; // you have return after doing the console
  }
  // ...
  console.log('query - outside', query);
  return MeasureData.find(query).count() > 0;
}

Can you try this and let me know if there is any change in output or not?

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda